document.write('<scr' + 'ipt src="http://img.t2cn.com/passport/js/util/GB2312.js" LANGUAGE="JavaScript"></scr' + 'ipt>');
document.write('<scr' + 'ipt src="scripts/validate.js" LANGUAGE="JavaScript"></scr' + 'ipt>');
document.write('<scr' + 'ipt src="scripts/encode.js" LANGUAGE="JavaScript"></scr' + 'ipt>');
var distId = "";
function changeGame(success_url,userNameValue,passwdValue){
	var ajax=getRequest();
	var gameId = document.getElementById("serviceId").value;
	var req="./getDist.action?serviceId="+gameId;
	
	ajax.onreadystatechange=function(){
			if(ajax.readyState==1){
			
			}else if(ajax.readyState==2){

			}else if(ajax.readyState==3){
				
			}else{
			   if(ajax.readyState==4){
			         var resultDoc=ajax.responseXML;
				     try{
				        var sta=resultDoc.documentElement.getElementsByTagName("status")[0].firstChild.data;
			            if(sta=="ok"){	
							// 返回正确信息
							
							// 清除原有数据
							var listBox=document.getElementById("districtId");
							for(var i=listBox.options.length-1;i>=0;i--){
								listBox.remove(i);
							}
							
							// 找到所有area节点放入数组
							var arr=ajax.responseXML.getElementsByTagName("area");
							// 遍历这个数组
							for(var i=0;i<arr.length;i++){
								// 找到每个area
							    var areaNode=arr[i];
							    
							    // Get id && name
								var id=areaNode.getElementsByTagName("id")[0].firstChild.data;
								var name=areaNode.getElementsByTagName("name")[0].firstChild.data;
				               
								// Create optionCtrl
								var optionCtrl=document.createElement("option");
								optionCtrl.setAttribute("value",id);
								optionCtrl.appendChild(document.createTextNode(name));
								
								// Refresh listBox
								listBox.appendChild(optionCtrl);	
							}
							distId = document.iform.districtId.value;							
						}
						else{
						
						}	
				     }catch(e){
					
				     }
			   }
			}
		}
	ajax.open("POST",req,true);
	ajax.send("");
}

function getTeam(){
	var gameId = document.getElementById("serviceId").value;
	if (document.getElementById("serviceId").value =='10'){
	    document.getElementById("viewTeam").style.display = "";
		var ajax=getRequest();
	    if(distId==""){
	       distId = document.iform.districtId.value;
	    }
		var userName = document.getElementById("loginName").value;
		alert(gameId);
		alert(distId);
		alert(userName);
		if(gameId!=0 && distId!=0 && userName!=""){
			var req="./getUserTeam.action?serviceId="+gameId+"&districtId="+distId+"&userName="+userName;
			
			ajax.onreadystatechange=function(){
					if(ajax.readyState==1){
					
					}else if(ajax.readyState==2){
		
					}else if(ajax.readyState==3){
						
					}else{
					   if(ajax.readyState==4){
					         var resultDoc=ajax.responseXML;
						     try{
						        var sta=resultDoc.documentElement.getElementsByTagName("status")[0].firstChild.data;
					            if(sta=="ok"){	
									// 返回正确信息
									
									// 清除原有数据
									var listBox=document.getElementById("team");
									for(var i=listBox.options.length-1;i>=0;i--){
										listBox.remove(i);
									}
									
									// 找到所有area节点放入数组
									var arr=ajax.responseXML.getElementsByTagName("area");
									// 遍历这个数组
									for(var i=0;i<arr.length;i++){
										// 找到每个area
									    var areaNode=arr[i];
									    
									    // Get id && name
										var id=areaNode.getElementsByTagName("id")[0].firstChild.data;
										var name=areaNode.getElementsByTagName("name")[0].firstChild.data;
						               
										// Create optionCtrl
										var optionCtrl=document.createElement("option");
										optionCtrl.setAttribute("value",id);
										optionCtrl.appendChild(document.createTextNode(name));
										
										// Refresh listBox
										listBox.appendChild(optionCtrl);	
									}							
								}
								else{
								
								}	
						     }catch(e){
							
						     }
					   }
					}
				}
			ajax.open("POST",req,true);
			ajax.send("");
	}
}else{
	document.getElementById("viewTeam").style.display = "none";
	return;
}
}

function Trim(str){
 if(str.charAt(0) == " "){
  str = str.slice(1);
  str = Trim(str);
 }
 return str;
 }
 
function strlen(str){
	var len;
	var t;
	len = 0;
	for (t=0;t<str.length;t++){
		if (str.charCodeAt(t)>255) len+=2; else len++;
	}
	return len;
}

function ltrim2(s){ 
 return s.replace( /^\s*/, ""); 
} 

function rtrim2(s){ 
 return s.replace( /\s*$/, ""); 
} 

function trim2(s){ 
 return rtrim2(ltrim2(s)); 
}